<?php

namespace app\admin\model;

use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
use think\facade\Db;

class WebReport extends BaseModel
{

    use SoftDelete;

    

    // 表名
    protected $name = 'web_report';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'online_time_text'
    ];
    
    /**
    * @param Model $row
    */
    protected static function onAfterInsert($row){
        $pk = $row->getPk();
        $row->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
    }

    



    public function getOnlineTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['online_time']) ? $data['online_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setOnlineTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    // 获取类型 web_label 表中type==1
    public function getTypeOne()
    {
        $list = Db::name('web_label')->field('id,name')->where('state',1)->select();
        return $list;
    }


}
